package jp.ac.kobe_u.cs.cream;

import jp.ac.kobe_u.cs.cream.*;
import java.util.*;

public class Equals extends Constraint {
    private Variable v[];

    public Equals(Network net, Variable v0, Variable v1) {
	this(net, new Variable[] {v0, v1});
    }

    public Equals(Network net, Variable v[]) {
	super(net);
	this.v = (Variable[])v.clone();
    }

    protected Constraint copy(Network net) {
	return new Equals(net, Constraint.copy(v, net));
    }

    protected boolean isModified() {
	return isModified(v);
    }

    protected boolean satisfy(Trail trail) {
	Domain d = v[0].getDomain();
	for (int i = 1; i < v.length; i++) {
	    d = d.cap(v[i].getDomain());
	    if (d.isEmpty())
		return false;
	}
	for (int i = 0; i < v.length; i++) {
	    v[i].updateDomain(d, trail);
	}
	return true;
    }

    public String toString() {
	return "Equals(" + Constraint.toString(v) + ")";
    }
}
